package com.xingyue.base.aspect;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;

import java.util.List;

/**
 * Created by binbin on 2017/7/23.
 */
@Aspect
@Component
@Order(1)
public class ValidParamAspect {
    @Autowired
    private ObjectMapper objectMapper;

    String getParamError(List<FieldError> fieldErrorList) {
        StringBuffer stringBuffer = new StringBuffer();
        fieldErrorList.forEach(item -> stringBuffer.append(String.format("field:[%1$s],description:[%2$s],rejected:'%3$s'.",
                item.getField(), item.getDefaultMessage(), item.getRejectedValue())));
        return stringBuffer.toString();
    }

    private void validBindingResult(BindingResult result) throws Exception{
        if(result.hasErrors()){

        }
    }
}
